<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <!-- 搜索 添加 -->
      <el-row :gutter="10">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="userlist.username" >
            <el-button slot="append" icon="el-icon-search" @click="getUserList"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible = true">添加用户</el-button>
        </el-col>
      </el-row>
      <!--用户列表区域-->
      <el-table :data="userlist" border stripe>
<!--        <el-table-column type="index"></el-table-column>-->
<!--        索引列-->
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="用户id" prop="id" ></el-table-column>//
        <el-table-column label="用户名" prop="username"></el-table-column>
        <el-table-column label="昵称" prop="nickname"></el-table-column>
        <el-table-column label="创建时间" prop="create_time"></el-table-column>
        <el-table-column label="更新时间" prop="update_time"></el-table-column>
        <el-table-column label="操作" width="180px">
          <template slot-scope="scope" >
            <!--            {{scope.row}}-->
            <el-tooltip effect="dark" content="修改按钮" placement="top">
              <!--               修改按钮-->
              <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除按钮" placement="top">
              <!--            删除按钮-->
              <el-button type="danger" icon="el-icon-setting" size="mini"></el-button>
            </el-tooltip>

            <el-tooltip effect="dark" content="分配角色" placement="top"  :enterable="false">
              <!--            分配角色按钮-->
              <el-button type="warning" icon="el-icon-delete" size="mini"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!--      分页区域-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.page_no"
        :page-sizes="[1,4, 6, 8]"
        :page-size="queryInfo.page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totle">
      </el-pagination>
      </el-card>
  </div>
</template>

<script>
import apiAll from "@/common/apiAll"

export default {
  data() {
    return {
      // 获取用户列表的参数对象
      queryInfo: {
        page_no: 1,
        page_size: 4
      },
      //用户列表
      userlist: [],
      //总行数
      totle: 0
    }
  },
  created() {
    this.getUserList()
  },
  methods: {
    getUserList() {
      apiAll.getUser(this.queryInfo).then(res => {
        // console.log(res);
        if (res.status !== 200) {
          return this.$message.error('获取用户列表失败！')
        }
        // console.log(res.data.data.count)
        this.userlist = res.data.data.list
        this.totle = res.data.data.count
      })
    },
    //监听pagesize改变的事件
    handleSizeChange(newSize){
      // console.log(newSize)
      this.queryInfo.page_size=newSize;
      this.getUserList();
    },
    //监听页码值改变得事件
    handleCurrentChange(newPage){
      console.log(newPage)
      this.queryInfo.page_no=newPage;
      this.getUserList();
    },
    //当前每页显示多少条数据
    currentPage(){
    },

  },
}
</script>

<style lang="less" scoped>
</style>
